package com.btkjgc.framework.report;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

/**
 * Created by HelloWorld on 2015/4/24.
 */
public class Combobox
{
	public static List<String> yearList(int year)
	{
		List<String> list = new ArrayList<String>();
		for (int i = year; i >= 2004; i--)
		{
			list.add(Integer.toString(i));
		}
		return list;
	}

	public static List<String> monthList()
	{
		List<String> list = new ArrayList<String>();
		for (int i = 1; i <= 12; i++)
		{
			list.add(Integer.toString(i));
		}

		return list;
	}

	// 当Controller返回给ftl后，里面的值将会定下来，而实际上当年份和月份确定下来后，天数是相应的需要变化的？？
	public static List<String> dayList(int year, int month, int day)
	{
		List<String> dayList = new ArrayList<String>();
		SimpleDateFormat sf = new SimpleDateFormat("yyyyMM");
		Calendar calendar = Calendar.getInstance();
		int curyeaar = calendar.get(Calendar.YEAR);
		int curmonth = calendar.get(Calendar.MONTH) + 1;
		int curday = calendar.get(Calendar.DAY_OF_MONTH);
		String y = String.format("%04d", year) + String.format("%02d", month);

		try
		{
			Date date = sf.parse(y);
			calendar.setTime(date);
			int max = calendar.getActualMaximum(5);
			if (year < curyeaar || (year == curyeaar && month < curmonth))
			{
				for (int i = 1; i <= max; i++)
				{
					dayList.add(Integer.toString(i));
				}
			}
			else
			{
				for (int i = curday; i >= 1; i--)
				{
					dayList.add(Integer.toString(i));
				}
			}
		}
		catch (ParseException e)
		{
			e.printStackTrace();
		}
		return dayList;

	}
}
